package com.cavalier.surtr.impl.ucCenter;

import com.alibaba.dubbo.config.annotation.Service;
import com.cavalier.surtr.commonBase.ProcessResult;
import com.cavalier.surtr.coreUtils.MD5Utils;
import com.cavalier.surtr.entity.DTO.ucCenter.UserDTO;
import com.cavalier.surtr.mapper.ucCenter.UserMapper;
import com.cavalier.surtr.rpcBO.ucCenter.UserBO;
import com.cavalier.surtr.rpcService.ucCenter.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * Created by archangle on 17/3/8.
 */
@Service
public class UserServiceImpl implements IUserService {

    private static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);


    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional
    public ProcessResult<UserBO> addUser(UserBO userBO) {
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(userBO, userDTO);
        userMapper.insertSelective(userDTO);
        userBO.setId(userDTO.getId());
        return ProcessResult.wrapSuccessfulResultForData(userBO);
    }

    @Override
    @Transactional
    public ProcessResult<String> getTest() {
        UserDTO userDTO = new UserDTO();
        userDTO.setGroupId(1);
        userDTO.setIsValid(1);
        userDTO.setLockTag(1);
        userDTO.setNickName("nick" + UUID.randomUUID().toString().substring(0, 4));
        String pwd = MD5Utils.md5Encode("12cctv315syb");
        userDTO.setPwd(pwd);
        userDTO.setRoleId(1);
        userDTO.setUserName("surtr");
        userDTO.setSuperiorId(0);
        userMapper.insertSelective(userDTO);
        return ProcessResult.wrapSuccessfulResultForData("hahaha" + userDTO.getPwd() + userDTO.getUserName() + MD5Utils.md5Encode(pwd));
    }
}
